﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows.Forms;
using App.Modelo;

namespace App.Git.Vista.Widget
{
    public partial class ListLineasReparacion : UserControl
    {
        public Equipo Equipo { get; set; }
        IList<LineaReparacion> lineas;
        [Bindable(true)]
        public IList<LineaReparacion> LineaReparacion
        {
            get
            {
                return lineas;
            }
            set
            {
                lineas = value;
                lineaReparacionBindingSource.Clear();

                if( value !=null)
                    foreach (var i in lineas)
                        lineaReparacionBindingSource.Add(i);
            }
        }
        public ListLineasReparacion()
        {
            InitializeComponent();
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            var form = new CrearLineaReparacion();
            var linea = form.GetNewLineaReparacion(Equipo);
            if (null != linea)
            {
                lineaReparacionBindingSource.Add(linea);
                LineaReparacion.Add(linea);
            }
        }

        private void toolStripButton3_Click(object sender, EventArgs e)
        {
            if (lineaReparacionBindingSource.Current is LineaReparacion)
            {
                var linea = lineaReparacionBindingSource.Current as LineaReparacion ;
                var form = new CrearLineaReparacion();
                form.GetNewLineaReparacion(Equipo, linea);
            }
        }

        private void lineaReparacionBindingSource_CurrentChanged(object sender, EventArgs e)
        {
            toolStripButton2.Enabled = toolStripButton3.Enabled = lineaReparacionBindingSource.Current is LineaReparacion;
        }

        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            if (lineaReparacionBindingSource.Current is LineaReparacion)
            {
                var linea = lineaReparacionBindingSource.Current as LineaReparacion;
                lineas.Remove(linea);
                lineaReparacionBindingSource.Remove(linea);
            }
        }
    }
}
